home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / CLRCHART.AML < prev    next >
Text File  |  1996-07-17  |  6KB  |  274 lines

  1. //--------------------------------------------------------------------
  2. // CLRCHART.AML
  3. // Color Chart, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Clrchart.dox for user help)
  6. //
  7. // This macro displays a color chart with color attribute codes in
  8. // decimal and hexidecimal.
  9. //
  10. // If Clrchart is run from within an edit window and a color is
  11. // selected, then the color description (i.e. 'cyan on black') is
  12. // entered into the edit window text at the cursor.
  13. //
  14. // Usage:
  15. //
  16. // Select this macro from the Macro List (on the Macro menu), or run it
  17. // from the macro picklist <shift f12>.
  18. //
  19. // When called as a utility from other macros, the following parameters
  20. // can be passed:
  21. //
  22. //   arg 3: Initial x-position on the screen, relative to 0,0
  23. //   arg 4: Initial y-position on the screen, relative to 0,0
  24. //   arg 5: Initial attibute to be selected
  25. //   arg 6: Object to send the 'oncolor' event to, when the color
  26. //          changes. When 'oncolor' is called, the new color attribute
  27. //          is passed as the first parameter.
  28. //
  29. // Clrchart is called as a utility from the Cfgcolor and Hilitewd
  30. // macros.
  31. //--------------------------------------------------------------------
  32.  
  33. include bootpath "define.aml"
  34.  
  35. constant display_str  = '  '
  36.  
  37. // define an array of color attribute names
  38. attrname = { "black"     "blue"        "green"        "cyan"
  39.              "red"       "magenta"     "brown"        "gray"
  40.              "darkgray"  "brightblue"  "brightgreen"  "brightcyan"
  41.              "brightred" "pink"        "yellow"       "white" }
  42.  
  43. variable basecolor, foreground, background, lforeground, lbackground,
  44.          xbackground, retvalue, colorstring
  45.  
  46. xposition    = arg 3
  47. yposition    = arg 4
  48. initialattr  = arg 5
  49. notifyobject = arg 6
  50.  
  51. if initialattr then
  52.   foreground = initialattr & 0fh
  53.   background = (initialattr & 0f0h) shr 4
  54.   if background > 7 then
  55.     background = background - 8
  56.     basecolor  = 128
  57.   end
  58. end
  59.  
  60. // inherit window handling from 'win' object
  61. settype "win"
  62.  
  63.  
  64. // create the color chart window
  65. createwindow
  66. setframe ">b"
  67. setcolor  border_color         color gray  on black
  68. setcolor  text_color           color black on black
  69. setcolor  border_flash_color   color brightgreen on black
  70. settitle "Color Chart"
  71. setwinctrl (if? basecolor "≡" "≡") 2
  72.  
  73. if xposition then
  74.   sizewindow xposition yposition xposition + 23 yposition + 17
  75.              "a1" '' (getprevwin)
  76. else
  77.   // center the window
  78.   width = 24
  79.   height = 18
  80.   ox = (getvidcols - width) / 2
  81.   oy = (getvidrows - height) / 2
  82.   sizewindow ox oy ox + width - 1 oy + height - 1 "ad"
  83. end
  84. setborder "1f"
  85.  
  86. // draw the color chart
  87. private function drawchart
  88.   variable b, f
  89.   gotoxy 1 1
  90.   for f = 0 to 15 do
  91.     for b = 0 to 7 do
  92.       writestr display_str  (b * 16 + f) + basecolor
  93.     end
  94.     writeline
  95.   end
  96.   gotoxy 19 17
  97.   writestr "  O" (color black on green)
  98.   writestr "k  " (color red   on green)
  99. end
  100.  
  101. drawchart
  102.  
  103.  
  104. private function draw
  105.  
  106.   // clear the old bracket cursor
  107.   if xbackground then
  108.     writestr display_str lforeground + (lbackground * 16) + basecolor   xbackground - 1
  109.   end
  110.  
  111.   attr = foreground + (background * 16) + basecolor
  112.   colorstring = attrname [foreground + 1] + ' on ' + attrname [background + 1 + (if? basecolor 8)]
  113.  
  114.   // write color info at the bottom of the chart
  115.   writestr ('[dec=' + attr + ',hex=' + (base attr 16) + ']'):-16
  116.            (color gray on black) 1 17
  117.   writestr  colorstring:-24 (color gray on black) 1 18
  118.  
  119.   // move the cursor to the appropriate color cell
  120.   xbackground = background * 3 + 2
  121.   gotoxy xbackground foreground + 1
  122.  
  123.   // write the bracket [ ] cursor
  124.   attr = (if? background + (if? basecolor 8) > brightblue black white) + (background * 16) + basecolor
  125.   writestr '[' attr  xbackground - 1
  126.   writestr ']' attr  xbackground + 1
  127.   gotoxy xbackground foreground + 1
  128.  
  129.   lforeground = foreground
  130.   lbackground = background
  131.  
  132.   // notify the caller of this macro
  133.   sendobject notifyobject "oncolor" (getattr)
  134. end
  135.  
  136. draw
  137. showcursor 50 99
  138.  
  139. // toggle background base color
  140. private function togglebase
  141.   if basecolor then
  142.     basecolor = 0
  143.     setwinctrl '≡' 2
  144.   else
  145.     basecolor = 128
  146.     setwinctrl '≡' 2
  147.   end
  148.   xbackground = 0
  149.   drawchart
  150.   draw
  151. end
  152.  
  153.  
  154. // local close function for this window
  155. function close (value)
  156.   // call 'close' in object 'win'
  157.   pass
  158.   retvalue = if? (arg) value -1
  159.   endprocess
  160. end
  161.  
  162. function "≡"
  163.   close
  164. end
  165.  
  166. // exit the chart
  167. key <esc>
  168.   close
  169. end
  170.  
  171. // exit the chart when switching windows
  172. function onkillfocus
  173.   close
  174. end
  175.  
  176. // enter the color description in an edit window and exit
  177. key <enter>
  178.   if not notifyobject then
  179.     queue "write" colorstring
  180.   end
  181.   close (getattr)
  182. end
  183.  
  184. // macro help
  185. macrofile = arg 1
  186. key <f1>
  187.   helpmacro macrofile
  188. end
  189.  
  190. event <lbutton> (m)
  191.   pass
  192.   case getregion
  193.     // client area
  194.     when 1
  195.       if virtorow <= 16 then
  196.         foreground = (virtorow - 1) mod 16
  197.       else
  198.         // Ok button
  199.         if not m and virtorow == 17 and virtocol >= 19 then
  200.           call <enter>
  201.         end
  202.         return
  203.       end
  204.       background = (virtocol - 1) / 3
  205.       draw
  206.     when 52
  207.       togglebase
  208.   end
  209. end
  210.  
  211. event <move>
  212.   pass
  213.   if (button? 1) and getregion == 1 then
  214.     send <lbutton> 1
  215.   end
  216. end
  217.  
  218. event <ldouble>
  219.   call <enter>
  220. end
  221.  
  222. // check for 'Ok' hotkey
  223. key <char> (c)
  224.   if icompare c 'k' then
  225.     call <enter>
  226.   else
  227.     pass
  228.   end
  229. end
  230.  
  231. // move the cursor around in the chart
  232. key <left>
  233.   if not background then
  234.     togglebase
  235.   end
  236.   background = if? background (background - 1) 7
  237.   draw
  238. end
  239.  
  240. key <right>
  241.   if background == 7 then
  242.     togglebase
  243.   end
  244.   background = (background + 1) mod 8
  245.   draw
  246. end
  247.  
  248. key <up>
  249.   foreground = if? foreground (foreground - 1) 15
  250.   draw
  251. end
  252.  
  253. key <down>
  254.   foreground = (foreground + 1) mod 16
  255.   draw
  256. end
  257.  
  258. // toggle background base color
  259. key <tab>
  260.   togglebase
  261. end
  262.  
  263. // toggle background base color
  264. key <shift tab>
  265.   togglebase
  266. end
  267.  
  268. // invoke the editor recursively
  269. // wait for endprocess to return here
  270. process
  271.  
  272. // return the ascii value
  273. return retvalue
  274.